package net.kong.sns.rest.client.model;

import java.util.Map;
import java.util.Set;

/**
 * @author <a href="mailto:lanhuai@gmail.com">Ning Yubin</a>
 * @version $Id: UserInfoImpl.java,v 1.2 2009/07/28 02:35:43 ningyubin Exp $
 */
public class UserInfoImpl extends AbstractJsonAppObject implements UserInfo {
    private long userId;
    private String username;
    private String nickname;
    private String sex;
    private String birthday;

    public long getUserId() {
        return userId;
    }

    public String getUsername() {
        return username;
    }

    public String getNickname() {
        return nickname;
    }

    public String getSex() {
        return sex;
    }

    public String getBirthday() {
        return birthday;
    }

    @Override
    protected void processJsonObject(Map<String, Object> stringObjectMap) {
        if (stringObjectMap != null) {
            Set<String> fields = getInitializedFields();
            for (String fieldName : fields) {
                Object o = stringObjectMap.get(fieldName);
                if (o != null) {
                    if (fieldName.equals(Field.USER_ID.toString())) {
                        this.userId = Long.parseLong((String) o);
                    } else if (fieldName.equals(Field.NAME.toString())) {
                        this.username = (String) o;
                    } else if (fieldName.equals(Field.NICKNAME.toString())) {
                        this.nickname = (String) o;
                    } else if (fieldName.equals(Field.SEX.toString())) {
                        this.sex = (String) o;
                    } else if (fieldName.equals(Field.BIRTHDAY.toString())) {
                        this.birthday = (String) o;
                    }
                }
            }
        }
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", nickname='" + nickname + '\'' +
                ", sex='" + sex + '\'' +
                ", birthday='" + birthday + '\'' +
                '}';
    }
}
